home *** CD-ROM | disk | FTP | other *** search
/ Freelog 121 / FreelogMagazineJuilletAout2014-No121.iso / Outils / Adobe-Air / adobe-air_13.exe / [0] / setup.swf / scripts / mx / binding / Binding.as < prev    next >
Text File  |  2014-03-27  |  7KB  |  216 lines

  1. package mx.binding
  2. {
  3.    import flash.utils.Dictionary;
  4.    import mx.collections.errors.ItemPendingError;
  5.    import mx.core.mx_internal;
  6.    
  7.    use namespace mx_internal;
  8.    
  9.    public class Binding
  10.    {
  11.       
  12.       mx_internal static const VERSION:String = "3.0.0.0";
  13.        
  14.       
  15.       mx_internal var destFunc:Function;
  16.       
  17.       mx_internal var srcFunc:Function;
  18.       
  19.       mx_internal var destString:String;
  20.       
  21.       mx_internal var document:Object;
  22.       
  23.       private var hasHadValue:Boolean;
  24.       
  25.       mx_internal var disabledRequests:Dictionary;
  26.       
  27.       mx_internal var isExecuting:Boolean;
  28.       
  29.       mx_internal var isHandlingEvent:Boolean;
  30.       
  31.       public var twoWayCounterpart:Binding;
  32.       
  33.       private var wrappedFunctionSuccessful:Boolean;
  34.       
  35.       mx_internal var _isEnabled:Boolean;
  36.       
  37.       public var uiComponentWatcher:int;
  38.       
  39.       private var lastValue:Object;
  40.       
  41.       public function Binding(param1:Object, param2:Function, param3:Function, param4:String)
  42.       {
  43.          super();
  44.          this.document = param1;
  45.          this.srcFunc = param2;
  46.          this.destFunc = param3;
  47.          this.destString = param4;
  48.          _isEnabled = true;
  49.          isExecuting = false;
  50.          isHandlingEvent = false;
  51.          hasHadValue = false;
  52.          uiComponentWatcher = -1;
  53.          BindingManager.addBinding(param1,param4,this);
  54.       }
  55.       
  56.       private function registerDisabledExecute(param1:Object) : void
  57.       {
  58.          if(param1 != null)
  59.          {
  60.             disabledRequests = mx_internal::disabledRequests != null ? mx_internal::disabledRequests : new Dictionary(true);
  61.             mx_internal::disabledRequests[param1] = true;
  62.          }
  63.       }
  64.       
  65.       protected function wrapFunctionCall(param1:Object, param2:Function, param3:Object = null, ... rest) : Object
  66.       {
  67.          var result:Object = null;
  68.          var thisArg:Object = param1;
  69.          var wrappedFunction:Function = param2;
  70.          var object:Object = param3;
  71.          var args:Array = rest;
  72.          wrappedFunctionSuccessful = false;
  73.          try
  74.          {
  75.             result = wrappedFunction.apply(thisArg,args);
  76.             wrappedFunctionSuccessful = true;
  77.             return result;
  78.          }
  79.          catch(itemPendingError:ItemPendingError)
  80.          {
  81.             itemPendingError.addResponder(new EvalBindingResponder(this,object));
  82.             if(BindingManager.debugDestinationStrings[mx_internal::destString])
  83.             {
  84.                trace("Binding: destString = " + mx_internal::destString + ", error = " + itemPendingError);
  85.             }
  86.          }
  87.          catch(rangeError:RangeError)
  88.          {
  89.             if(BindingManager.debugDestinationStrings[mx_internal::destString])
  90.             {
  91.                trace("Binding: destString = " + mx_internal::destString + ", error = " + rangeError);
  92.             }
  93.          }
  94.          catch(error:Error)
  95.          {
  96.             if(error.errorID != 1006 && error.errorID != 1009 && error.errorID != 1010 && error.errorID != 1055 && error.errorID != 1069)
  97.             {
  98.                throw error;
  99.             }
  100.             if(BindingManager.debugDestinationStrings[mx_internal::destString])
  101.             {
  102.                trace("Binding: destString = " + mx_internal::destString + ", error = " + error);
  103.             }
  104.          }
  105.          return null;
  106.       }
  107.       
  108.       public function watcherFired(param1:Boolean, param2:int) : void
  109.       {
  110.          var commitEvent:Boolean = param1;
  111.          var cloneIndex:int = param2;
  112.          if(mx_internal::isHandlingEvent)
  113.          {
  114.             return;
  115.          }
  116.          try
  117.          {
  118.             isHandlingEvent = true;
  119.             execute(cloneIndex);
  120.          }
  121.          finally
  122.          {
  123.             isHandlingEvent = false;
  124.          }
  125.       }
  126.       
  127.       private function nodeSeqEqual(param1:XMLList, param2:XMLList) : Boolean
  128.       {
  129.          var _loc4_:uint = 0;
  130.          var _loc3_:uint = param1.length();
  131.          if(_loc3_ == param2.length())
  132.          {
  133.             _loc4_ = 0;
  134.             while(_loc4_ < _loc3_ && param1[_loc4_] === param2[_loc4_])
  135.             {
  136.                _loc4_++;
  137.             }
  138.             return _loc4_ == _loc3_;
  139.          }
  140.          return false;
  141.       }
  142.       
  143.       mx_internal function set isEnabled(param1:Boolean) : void
  144.       {
  145.          _isEnabled = param1;
  146.          if(param1)
  147.          {
  148.             processDisabledRequests();
  149.          }
  150.       }
  151.       
  152.       private function processDisabledRequests() : void
  153.       {
  154.          var _loc1_:* = null;
  155.          if(mx_internal::disabledRequests != null)
  156.          {
  157.             for(_loc1_ in mx_internal::disabledRequests)
  158.             {
  159.                execute(_loc1_);
  160.             }
  161.             disabledRequests = null;
  162.          }
  163.       }
  164.       
  165.       public function execute(param1:Object = null) : void
  166.       {
  167.          var o:Object = param1;
  168.          if(!mx_internal::isEnabled)
  169.          {
  170.             if(o != null)
  171.             {
  172.                registerDisabledExecute(o);
  173.             }
  174.             return;
  175.          }
  176.          if(mx_internal::isExecuting || twoWayCounterpart && twoWayCounterpart.isExecuting)
  177.          {
  178.             hasHadValue = true;
  179.             return;
  180.          }
  181.          try
  182.          {
  183.             isExecuting = true;
  184.             wrapFunctionCall(this,innerExecute,o);
  185.          }
  186.          finally
  187.          {
  188.             isExecuting = false;
  189.          }
  190.       }
  191.       
  192.       mx_internal function get isEnabled() : Boolean
  193.       {
  194.          return mx_internal::_isEnabled;
  195.       }
  196.       
  197.       private function innerExecute() : void
  198.       {
  199.          var _loc1_:Object = wrapFunctionCall(mx_internal::document,mx_internal::srcFunc);
  200.          if(BindingManager.debugDestinationStrings[mx_internal::destString])
  201.          {
  202.             trace("Binding: destString = " + mx_internal::destString + ", srcFunc result = " + _loc1_);
  203.          }
  204.          if(hasHadValue || wrappedFunctionSuccessful)
  205.          {
  206.             if(!(lastValue is XML && lastValue.hasComplexContent() && lastValue === _loc1_) && !(lastValue is XMLList && lastValue.hasComplexContent() && _loc1_ is XMLList && nodeSeqEqual(lastValue as XMLList,_loc1_ as XMLList)))
  207.             {
  208.                mx_internal::destFunc.call(mx_internal::document,_loc1_);
  209.                lastValue = _loc1_;
  210.                hasHadValue = true;
  211.             }
  212.          }
  213.       }
  214.    }
  215. }
  216.